#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 检查SenseVoice模型是否正确加载

import os
import sys
from funasr import AutoModel

def check_model():
    """检查模型是否正确加载"""
    print("=== 开始检查模型 ===")
    
    # 设置模型路径
    model_path = "models/iic/SenseVoiceSmall"
    vad_model_path = "models/iic/speech_fsmn_vad_zh-cn-16k-common-pytorch"
    
    # 检查模型路径是否存在
    print(f"模型路径: {os.path.abspath(model_path)}")
    print(f"VAD模型路径: {os.path.abspath(vad_model_path)}")
    print(f"模型路径是否存在: {os.path.exists(model_path)}")
    print(f"VAD模型路径是否存在: {os.path.exists(vad_model_path)}")
    
    # 列出模型目录内容
    if os.path.exists(model_path):
        print(f"模型目录内容: {os.listdir(model_path)}")
    if os.path.exists(vad_model_path):
        print(f"VAD模型目录内容: {os.listdir(vad_model_path)}")
    
    # 尝试加载模型
    try:
        print("开始加载模型...")
        model = AutoModel(model=model_path,
                         vad_model=vad_model_path,
                         vad_kwargs={"max_single_segment_time": 30000},
                         trust_remote_code=True)
        print("模型加载成功!")
        return True
    except Exception as e:
        print(f"模型加载失败: {str(e)}")
        return False
    finally:
        print("=== 模型检查完成 ===")

if __name__ == "__main__":
    success = check_model()
    if not success:
        sys.exit(1) 